#!/usr/bin/env python

import unittest

from amlnextbus.direction import Direction

class TestDirection(unittest.TestCase):
    def setUp(self):
        self.direction = Direction('F')

    def testParseDirection(self):
        testStr1 = 'parent.addOption(directionSelector, "Inbound to Church & Market", "F__IBMRKT", false, true);'
        (name, symbol, restOfStr) = self.direction.parseDirection(testStr1)

        self.assertEquals(name, "Inbound to Church & Market")
        self.assertEquals(symbol, "F__IBMRKT")

        testStr2 = """
    parent.addOption(directionSelector, "Inbound to Fisherman's Wharf", "F__IBCTRO", false, false);

    parent.addOption(directionSelector, "Outbound to Balboa Park Station", "F__OBGNVA", false, false);

    parent.addOption(directionSelector, "Outbound to Castro Station", "F__OBCTRO", false, false);
"""
        expectedNameArr = ["Inbound to Fisherman's Wharf", 
                           "Outbound to Balboa Park Station",
                           "Outbound to Castro Station"]
        expectedSymbolArr = ["F__IBCTRO", "F__OBGNVA", "F__OBCTRO"]

        (name, symbol, restOfHtmlStr) = self.direction.parseDirection(testStr2)
        i = 0
        while (restOfHtmlStr != None):
            self.assertEquals(name, expectedNameArr[i])
            self.assertEquals(symbol, expectedSymbolArr[i])
        
            i += 1
            (name, symbol, restOfHtmlStr) = self.direction.parseDirection(restOfHtmlStr)

    def testLoadDirections(self):
        self.assertTrue(len(self.direction.nameArr) > 0)
        self.assertTrue(len(self.direction.symbolArr) > 0)

    def testGetName(self):
        self.assertEquals(self.direction.getName("F__IBMRKT"), "Inbound to Church & Market")
        self.assertEquals(self.direction.getName("F__IBCTRO"), "Inbound to Fisherman's Wharf")
        self.assertEquals(self.direction.getName("F__OBGNVA"), "Outbound to Balboa Park Station")

    def testGetSymbol(self):
        self.assertEquals(self.direction.getSymbol("Inbound to Fisherman's Wharf"), "F__IBCTRO")
        self.assertEquals(self.direction.getSymbol("Outbound to Balboa Park Station"), "F__OBGNVA")
        self.assertEquals(self.direction.getSymbol("Outbound to Castro Station"), "F__OBCTRO")


if __name__ == '__main__':
    unittest.main()


